<template>
  <div class="top-container">
    <div class="top-top"></div>
    <div class="top-main">
      <div class="icon"></div>
      <div class="dividing-line"></div>
      <div class="main-title">迅航<br>News</div>
      <div class="sub-title">--武大新闻整合平台</div>
      <div class="main-search">
        <div class="search-box">
          <el-input
              v-model="searchQuery"
              @input="handleSearch"
              class="custom-input"
              placeholder="搜索文章"
              title="文章搜索"
              clearable
          />
        </div>
        <div class="search-icon" @click="onSearch"></div>
      </div>
    </div>
    <div class="top-background"></div>
  </div>
  <div class="main-container">
    <div class="news-container">
      <div class="news-title">这是新闻的标题</div>
      <div class="news-meta">
        <div class="meta-author">来源/作者：</div>
        <div class="meta-time">发布时间：</div>
        <div class="meta-views">浏览量：</div>
        <div class="meta-back-home">回到首页</div>
      </div>
      <div class="news-dividing-line"></div>
      <div class="abstract-container">
        这是摘要
      </div>
      <div class="news-image"></div>
      <div class="news-content">这是正文</div>
    </div>
    <div class="related-container">
      <div class="related-box">
        <div class="related-header">
          <div class="related-header-icon"></div>
          <div class="related-header-title">相关阅读</div>
        </div>
        <div class="related-dividing-line"></div>
        <div class="news-list">
          <div
              v-for="(item, index) in newsItems"
              :key="index"
              class="news-item"
          >
            <div class="related-content">
              <h3>{{ item.title }}</h3>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  font-family:Arial,sans-serif;
  background-color: #f5f5f5;
  color: #0e0d0d;
  line-height: 1.6;
}
.top-container {
  width: 1920px;
  margin-left:0;
  padding: 0 0;
}
.top-top{
  height:50px;
  background-color: #02A7F0;
  opacity: 0.5;
  border:1px solid #02A7F0;
}
.top-main{
  display: flex;
  padding: 15px 100px;
  height: 100px;
  background-color: white;
}
.top-background{
  position: relative;
  width: 1920px;
  height: 200px;
  background-color: rgb(2, 167, 240,0.34); /* 你可以改颜色或透明度 */
  border:1px solid #797979;
}
.top-background::after {
  position: absolute;
  content: "";
  width: 100%; height: 100%;
  background-image: url('@/assets/R-C.jpg');
  opacity: 0.2;
  background-size: 100% 100%;
  overflow: hidden;
  border:1px solid #797979;
  z-index: 1;
}
.icon{
  margin-left:32px;
  width:70px;
  height:70px;
  background-image: url("@/assets/whu_logo.ico");
  background-size: cover;  /* 根据需求设置 */
  background-position: center;
  background-repeat: no-repeat;
}
.dividing-line{
  margin:5px 15px;
  height: 60px;
  width: 1px;
  border:1px solid #797979;
}
.main-title{
  margin:5px 9px;
  width: 80px;
  height:60px;
  font-size:25px;
  line-height: 29px;
}
.sub-title{
  width: 300px;
  height:40px;
  padding-top: 8px;
  margin-top:30px;
  margin-left:-16px;
  color: #8080FF;
  opacity: 0.86;
  font-size: 15px;
}
.main-search{
  display: flex;
  width: 350px;
  height: 50px;
  margin-left: 496px;
  margin-top: 10px;
  background: #f2f2f2;
  border: 1px solid #797979;
  border-radius: 40px;
}
.search-box{
  width: 100%;
  height: 100%;
  padding:10px 30px;
  color: #555555;
  font-size: 15px;
  opacity: 0.8;
}
.search-icon{
  margin-top: 10px;
  margin-right: 18px;
  height: 30px;
  width:30px;
  background:url('@/assets/搜索.png') no-repeat center;
  background-size: cover;  /* 根据需求设置 */
}
.search-icon:hover{
  background-color: rgba(43, 84, 131, 0.1);
}
.custom-input >>> .el-input__wrapper {
  border: none;
  box-shadow: none;
  background-color: transparent; /* 继承外部容器背景色 */
}

.custom-input >>> input {
  background-color: transparent;
  color: #333; /* 字体颜色 */
}
.main-container{
  line-height: 28px;
  background-color: #F2F2F2;
  width: 100%;
  display: flex;

}
.news-container{
  min-height: 500px;
  background-color: white;
  width: 1011px;
  padding-left:80px;
}
.news-title{
  padding-top:21px;
  margin-top: 29px;
  width: 1000px;
  height: 100px;
  text-align: center;
  font-size: 37px;
}
.news-meta{
  font-size: 15px;
  display: flex;
  height:17px;

}
.meta-author{
  width: 300px;
}
.meta-time{
  width: 300px;
}
.meta-views{
  width: 300px;
}
.meta-back-home{
  font-size: 3px;
  cursor: pointer;
  width: 300px;
}
.meta-back-home:hover{
  color:#8080FF;
  text-decoration-line: underline;
  text-decoration-color: #8080FF;
}
.news-dividing-line{
  margin-top: 22px;
  width:900px;
  height: 1px;
  border:1px solid #797979;
}
.abstract-container{
  width: 900px;
  font-size: 18px;
  margin-top:23px;
}
.news-image{
  margin-left: 170px;
  width: 500px;
  height:400px;
  align-items: center;
  background-image: url("@/assets/DF42FD3E2DA95209D3E3D5394B6_7FF55428_71207.jpg");
  background-size: contain;  /* 根据需求设置 */
  background-position: center;
  background-repeat: no-repeat;
}
.news-content{
  width: 900px;
  font-size: 18px;
}
.related-container{
  width: 489px;
  padding-left:200px;
  padding-top: 100px;
}
.related-box{
  width: 288px;
  height: 400px;
  border: 1px solid #797979;
  border-radius: 20px;
  background-color: white;
}
.related-header{
  margin:30px 25px;
  display: flex;
  font-size: 20px;
}
.related-header-title{
  margin-left: 12px;
  font-size: 20px;
}
.related-header-icon{
  height: 30px;
  width: 30px;
  background-image: url("@/assets/书籍 (2).png");
  background-size: cover;  /* 根据需求设置 */
  background-position: center;
  background-repeat: no-repeat;
}
.related-dividing-line{
  margin-left: 29px;
  border: 1px solid #797979;
  height: 1px;
  width: 228px;
}
.news-list{
  margin-left: 29px;
  width: 228px;
  height: 500px;
}
.related-content{
  width: 200px;
  font-size: 14px;
}
.news-item {
  display: flex;
  align-items: center;
  padding: 5px 20px;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  cursor: pointer;
  border-left: 4px solid transparent;
}
.news-item:hover {
  text-decoration: underline;
}
</style>
<script>
import { ref } from 'vue'
const searchText = ref('')
import axios from 'axios';

export default {
  setup() {
    const newsItems = ref([
      {
        id: 1,
        title: 'Vue3 组合式 API 全面解析：从入门到精通',
      },
      {
        id: 2,
        title: '前端性能优化：Vue3 项目实战经验分享',
      }
    ])

    return {
      newsItems // 👈 一定要 return 出去
    }
  },
  data() {
    return {
      searchQuery: '', // 搜索词
      results: [] // 搜索结果
    };
  },
  methods: {
    handleSearch() {
      // 监听搜索框输入变化，您可以选择实时搜索
    },
    async onSearch() {
      if (this.searchQuery) {
        try {
          // 发起请求到后端，假设API为 /api/search
          const response = await axios.get('/api/search', {
            params: { query: this.searchQuery }
          });
          this.results = response.data; // 设置搜索结果
        } catch (error) {
          console.error("搜索失败:", error);
        }
      }
    }
  }
};
</script>